package com.leen.admin.controller;


import com.leen.admin.dto.DeptDto;
import com.leen.admin.dto.RoleDto;
import com.leen.admin.dto.RoleSaveDTO;
import com.leen.admin.entity.Role;
import com.leen.admin.repository.RoleRepository;
import com.leen.admin.service.RoleService;
import com.leen.common.vo.ResponseVO;
import com.leen.common.vo.ResultEnum;
import com.leen.common.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * 角色接口
 * @author xjl
 * @date 2021-05-19
 */
@RestController
@Api(tags = "角色接口API")
@RequestMapping(value = "/admin")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Autowired
    private RoleRepository roleRepository;

    @ApiOperation(value = "查询数据")
    @GetMapping(value = "/role/data")
    public ResultVO<Role> search(RoleDto roleDto){
        return ResultVO.success(this.roleService.search(roleDto));
    }

    @ApiOperation(value = "保存数据")
    @PostMapping(value = "/role/save")
    public ResultVO<String> save(@RequestBody RoleSaveDTO roleSaveDTO){
      boolean result=this.roleService.save(roleSaveDTO);
        return result? ResultVO.success(ResultEnum.DB_SUCCESS):ResultVO.failed(ResultEnum.DB_FAILED);
    }



    @ApiOperation(value = "分页查询")
    @PostMapping(value = "/role/searchPage")
    public ResultVO<String> searchPage(RoleDto roleDto){
        ResponseVO search = this.roleService.search(roleDto);
        return  ResultVO.success(search);
    }





}
